package com.yuzhenxin.bookstore.dao;

import com.yuzhenxin.bookstore.domain.Category;
import com.yuzhenxin.bookstore.tools.jdbc.TxQueryRunner;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class CategoryDao {

    private final QueryRunner queryRunner = new TxQueryRunner();

    /**
     * 查询所有分类
     */
    public List<Category> findAll() {
        try {
            String sql = "SELECT * FROM category";
            return queryRunner.query(sql, new BeanListHandler<>(Category.class));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
